<template>
    <div id="sshart">
        <div class="logo">
            <el-button :icon="ArrowLeft" style="position: fixed;left: 23px;top: 15px;z-index: 999;" class="m_elbtn"
                @click="backhns()">返回上级</el-button>
            <img style="margin: 0 auto;height: 50px;display: block;" src="/img/new_logo.png" alt="">
            <div style="
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            line-height: 30px;
            font-size: 26px;
            font-weight: bold;
            background: linear-gradient(to top, #65B3DF, #F1F2F4);;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            letter-spacing: 5px;">{{ ctname }}人口与城镇化数据统计</div>
            <div style="position: absolute;
            right: 40px;
            top: 50%;
            transform: translate(0,-30%);
            color: #00DEFF;
            line-height: 30px;
            display: flex;
            align-items: center;">
                <img style="margin-right: 10px;" src="/images/fwico_01.png" alt="">
                <span style="margin-right: 10px;">
                    今日：{{ CountNum.todady }}{{ todayunit }}
                </span>
                <img style="margin-right: 10px;" src="/images/fwico_02.png" alt="">
                <span>总计：{{ CountNum.total }}{{ totalunit }}</span>
            </div>
        </div>
        <div id="charts" class="m_sschart">

            <div class="Chartleft">
                <div class="charscon">
                    <div class="chartitle">常住人口数</div>
                    <img src="/img/ksh33.png" alt="">
                    <div ref="rkref" id="allRK"></div>
                </div>
                <div class="charscon">
                    <div class="chartitle">城镇化率</div>
                    <img src="/img/ksh33.png" alt="">
                    <div ref="czhl" id="CZHl"></div>
                </div>
                <div class="charscon">
                    <div class="chartitle">全省GDP情况</div>
                    <img src="/img/ksh33.png" alt="">
                    <div ref="gdp" id="allGDP"></div>
                </div>
            </div>
            <div class="Chartmiddle">
                <div class="numbercount">
                    <div class="numbercc">
                        <div class="dgtitle">常住人口(万人)</div>
                        <div class="dgnumber">{{ CZcount }}</div>
                    </div>
                    <div class="numbercc">
                        <div class="dgtitle">就业人口(万人)</div>
                        <div class="dgnumber">{{ Jycount }}</div>
                        <!-- <numberroll :numm="RKcount" :numLen="RKcount.toString().length"></numberroll> -->
                    </div>
                    <div class="numbercc">
                        <div class="dgtitle">城镇化(%)</div>
                        <div class="dgnumber">{{ CZHlv }}</div>
                    </div>
                    <div class="numbercc">
                        <div class="dgtitle">出生率(%)</div>
                        <div class="dgnumber">{{ CSlv }}</div>
                    </div>
                    <div class="numbercc">
                        <div class="dgtitle">死亡率(%)</div>
                        <div class="dgnumber">{{ SWlv }}</div>
                    </div>
                </div>
                <div class="mapcon">
                    <div class="datatitle">
                        {{ currenyear }}年{{ ctname }}{{ m_title }}
                    </div>
                    <!-- <el-button style="position: absolute;top: 4px;left: 4px;" type="success" size="small" @click="backhns()">返回上级</el-button> -->
                    <img class="lt" src="/img/ksh42.png" alt="">
                    <img class="rt" src="/img/ksh43.png" alt="">
                    <img class="lb" src="/img/ksh44.png" alt="">
                    <img class="rb" src="/img/ksh45.png" alt="">
                    <div style="position: absolute;top: 40px;left: 10px;width: 100%;text-align: center;color: white;z-index: 9999;font-size: small;color: #00DEFF;">
                        提示：本数据来源于
                        <span style="cursor: pointer;" class="yearlink" @click="toNewPage()">《河南省统计年鉴》</span>
                        ，如有误差以河南省统计局官方发布数据为准。
                    </div>
                    
                    <div ref="mapmain" id="mapmain"></div>
                    <div class="datacon">
                        <div class="citylist" v-for="(item, index) in rkdata">
                            <span>[{{ index + 1 }}]</span>
                            <span>{{ item.name }}:</span>
                            <span>{{ item.value }}</span>
                        </div>
                    </div>
                </div>

            </div>
            <div class="Chartright">
                <div class="charscon">
                    <div class="chartitle">人口密度</div>
                    <img src="/img/ksh33.png" alt="">
                    <div ref="RKdensity" id="RKdensity"></div>
                </div>
                <div class="charscon">
                    <div class="chartitle">出生率/死亡率</div>
                    <img src="/img/ksh33.png" alt="">
                    <div ref="natality" id="natality"></div>
                </div>
                <div class="charscon">
                    <div class="chartitle">就业人口</div>
                    <img src="/img/ksh33.png" alt="">
                    <div ref="mortality" id="mortality"></div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { onMounted, reactive, ref } from 'vue';
import { ArrowLeft } from '@element-plus/icons-vue';
import $sys from '../../api/sys';
import * as echarts from 'echarts';
import { useRouter } from 'vue-router';
import axios from 'axios';
import numberroll from '../../components/numberroll.vue';
const $router = useRouter();
const mapmain = ref();
const rkref = ref();
const czhl = ref();
const gdp = ref();
const RKdensity = ref();
const natality = ref();
const mortality = ref();
const GDPx = ref([]);
const RKx = ref([]);
const RKcount = ref(0);
const CZcount = ref(0);
const CZHlv = ref(0);
const CSlv = ref(0);
const SWlv = ref(0);
const Jycount = ref(0);
const currenyear = ref(2023);
const ctcode = ref(localStorage.getItem('ctcode'));
const ctname = ref(localStorage.getItem('ctname'));
const CountNum=ref({
    todady:0,
    total:0
})
const todayunit=ref('人次');
const totalunit=ref('人次');
onMounted(() => {
    getRKnumber(2023, '人口');
    getHisYear(2023);
    getpryear(2023, ctcode.value);
    getHisGDP();
    getCount();
});
function getCount(){
    $sys.getCount().then(res=>{
        if(res.code==200){
            if(Number(res.data.today)>=10000){
                todayunit.value='万人次';
            }else if(Number(res.data.today)>=100000000){
                todayunit.value='亿人次';
            }
            if(Number(res.data.total)>=10000){
                totalunit.value='万人次';
            }else if(Number(res.data.total)>=100000000){
                totalunit.value='亿人次';
            }
            CountNum.value.todady=res.data.today;
            CountNum.value.total=res.data.total;
        }
    })
}
function toNewPage() {
    window.open('https://www.henan.gov.cn/zwgk/zfxxgk/fdzdgknr/tjxx/tjnj/')
}
function backhns() {
    $router.replace({
        name: 'chart'
    })
}
//地图数据
const rkdata = ref([]);
//常住人数
const czrsdata = ref([]);
//总人口数
const zrsdata = ref([]);
//城镇化率
const czh = ref([]);
//GDP
const GDP = ref([]);
//人口密度
const rkmd = ref([]);
//出生率
const csl = ref([]);
//死亡率
const swl = ref([]);
//就业人口
const employment = ref([])
const scale = ref([
    { start: 100, end: 400 }, { start: 50, end: 100 },
    { start: 30, end: 50 }, { start: 20, end: 30 },
    { start: 10, end: 20 }, { start: 0, end: 10 },
]);
const GDPquery = reactive({});
function getHisGDP() {
    GDPquery.ad_code = ctcode.value;
    $sys.HisYearGDPData(GDPquery).then(res => {
        if (res.code == 200) {
            GDPx.value = [];
            GDP.value = [];
            res.data.forEach((item, index) => {
                let obj = {};
                GDPx.value.push(item.year);
                obj.value = item.value;
                obj.name = item.year;
                GDP.value.push(obj);
            });
            initGDP();
        }
    });
}
function initGDP() {
    var myChart = echarts.init(gdp.value);
    let option = {
        color: ['#66FFCC'],
        legend: {
            data: ['GDP(亿元)'],
            align: 'left',
            textStyle: {
                color: '#fff'
            }
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            x: 40,
            y: 30,
            x2: 5,
            y2: 20

        },
        calculable: true,
        xAxis: [{
            type: 'category',
            data: GDPx.value,
            axisLabel: {
                color: "#FFF" //刻度线标签颜色
            }
        }],
        yAxis: [
            {
                type: "value",
                min: "30000",
                axisLabel: {
                    color: "#FFF" //刻度线标签颜色
                }
            }
        ],
        series: [
            {
                name: 'GDP(亿元)',
                type: 'bar',
                barWidth: '40%',
                data: GDP.value,
                color: "#5581fd"
            }
        ]
    };
    myChart.setOption(option);
}

const Rkquery = reactive({});
function getHisYear(year) {
    RKx.value = [];
    Rkquery.ad_code = ctcode.value;
    czrsdata.value = [];
    zrsdata.value = [];
    czh.value = [];
    rkmd.value = [];
    csl.value = [];
    swl.value = [];
    employment.value = [];
    $sys.HisYearRkData(Rkquery).then(res => {
        currenyear.value = year;
        res.data.forEach((item, index) => {
            RKx.value.push(item.year);
            let czrsdataobj = {};
            let zrsdataobj = {};
            let czhobj = {};
            let rkmdobj = {};
            let cslobj = {};
            let swlobj = {};
            let employobj = {};
            czrsdataobj.name = item.year;
            zrsdataobj.name = item.year;
            czhobj.name = item.year;
            rkmdobj.name = item.year;
            cslobj.name = item.year;
            swlobj.name = item.year;
            employobj.name = item.year;

            czrsdataobj.value = item.resident;
            zrsdataobj.value = item.total;
            czhobj.value = item.urbanization;
            rkmdobj.value = item.density;
            cslobj.value = item.birth;
            swlobj.value = item.death;
            employobj.value = item.employment;

            czrsdata.value.push(czrsdataobj);
            zrsdata.value.push(zrsdataobj);
            czh.value.push(czhobj);
            rkmd.value.push(rkmdobj);
            csl.value.push(cslobj);
            swl.value.push(swlobj);
            employment.value.push(employobj);
        });
        initRK();
        initCZH();
        initRKdensity();
        initnatality();
        initmortality();
    });
}
const mapquery = reactive({});

function getpryear(year, code) {
    let obj = {};
    obj.year = year;
    obj.ad_code = code;
    $sys.RKnumber(obj).then(res => {
        if (res.code == 200) {
            RKcount.value = res.data.total;
            CZcount.value = res.data.resident;
            CZHlv.value = res.data.urbanization;
            CSlv.value = res.data.birth;
            SWlv.value = res.data.death;
            Jycount.value = res.data.employment;
        }
    });
}
const m_title = ref('常住人口(万人)');
function getRKnumber(year, type) {
    mapquery.year = year;
    mapquery.ad_code = ctcode.value;
    currenyear.value = year;
    rkdata.value = [];
    $sys.SRKnumber(mapquery).then(res => {
        res.data.forEach((item, index) => {
            let obj = {};
            obj.name = item.ad_name;
            if (type == '人口') {
                obj.value = item.resident;
                m_title.value = '常住人口(万人)';
            } else if (type == '城镇化率') {
                obj.value = item.urbanization;
                m_title.value = '城镇化率(%)';
            } else if (type == '出生率') {
                obj.value = item.birth;
                m_title.value = '出生率(%)';
            } else if (type == '死亡率') {
                obj.value = item.death;
                m_title.value = '死亡率(%)';
            }
            obj.code = item.ad_code;
            rkdata.value.push(obj);
        });
        initmap();
    });
}
function initRK() {
    var myChart = echarts.init(rkref.value);
    let option = {
        color: ['#3398DB'],
        legend: {
            data: ['常住人数(万人)'],
            align: 'left',
            textStyle: {
                color: '#fff'
            }
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            x: 40,
            y: 30,
            x2: 5,
            y2: 20
        },
        calculable: true,
        xAxis: [{
            type: 'category',
            data: RKx.value,
            axisLabel: {
                color: "#FFF" //刻度线标签颜色
            }
        }],
        yAxis: [{
            type: 'value',
            axisLabel: {
                color: "#FFF" //刻度线标签颜色
            }
        }],
        series: [
            // {
            //     name: '总人口(万人)',
            //     type: 'bar',
            //     barWidth: '40%',
            //     data: zrsdata.value,
            //     color: "#5581fd"
            // },
            {
                name: '常住人数(万人)',
                type: 'bar',
                barWidth: '40%',
                data: czrsdata.value,
                color: "#FFFF66"
            }
        ]
    };
    myChart.setOption(option);
    myChart.on('click', (e) => {

        // getHisYear(e.data.name);
        getpryear(e.data.name, ctcode.value);
        scale.value = [
            { start: 100, end: 400 }, { start: 50, end: 100 },
            { start: 30, end: 50 }, { start: 20, end: 30 },
            { start: 10, end: 20 }, { start: 0, end: 10 },
        ];
        getRKnumber(e.data.name, '人口');
    });
}
function initCZH() {
    var myChart = echarts.init(czhl.value);
    let option = {
        color: ['#00FF00'],
        legend: {
            data: ['城镇化率(%)'],
            align: 'left',
            textStyle: {
                color: '#fff'
            }
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            x: 40,
            y: 30,
            x2: 5,
            y2: 20
        },
        calculable: true,
        xAxis: [{
            type: 'category',
            data: RKx.value,
            axisLabel: {
                color: "#FFF" //刻度线标签颜色
            }
        }],
        yAxis: [
            {
                type: "value",
                min: "35",
                axisLabel: {
                    color: "#FFF" //刻度线标签颜色
                }
            }
        ],
        series: [
            {
                name: '城镇化率(%)',
                type: 'line',
                barWidth: '40%',
                data: czh.value,
                color: "#5581fd"
            }
        ]
    };
    myChart.setOption(option);
    myChart.on('click', function (e) {
        getpryear(e.data.name, ctcode.value);
        scale.value = [
            { start: 80, end: 100 }, { start: 60, end: 80 },
            { start: 50, end: 60 }, { start: 40, end: 50 },
            { start: 30, end: 40 }, { start: 0, end: 30 },
        ];
        getRKnumber(e.data.name, '城镇化率');
    });
}
function initRKdensity() {
    var myChart = echarts.init(RKdensity.value);
    let option = {
        color: ['#00FF00'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            x: 40,
            y: 30,
            x2: 5,
            y2: 20
        },
        calculable: true,
        xAxis: [{
            type: 'category',
            data: RKx.value,
            axisLabel: {
                color: "#FFF" //刻度线标签颜色
            }
        }],
        yAxis: [
            {
                type: "value",
                min: "35",
                axisLabel: {
                    color: "#FFF" //刻度线标签颜色
                }
            }
        ],
        series: [
            {
                name: '人口密度(人)',
                type: 'bar',
                barWidth: '40%',
                data: rkmd.value,
                color: "#5581fd"
            }
        ]
    };
    myChart.setOption(option);
}
function initnatality() {
    var myChart = echarts.init(natality.value);
    let option = {
        color: ['#00FF00'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        legend: {
            data: ['出生率(%)', '死亡率(%)'],
            align: 'left',
            textStyle: {
                color: '#fff'
            }
        },
        grid: {
            x: 40,
            y: 30,
            x2: 5,
            y2: 20
        },
        calculable: true,
        xAxis: [{
            type: 'category',
            data: RKx.value,
            axisLabel: {
                color: "#FFF" //刻度线标签颜色
            }
        }],
        yAxis: [
            {

                type: "value",
                min: "0",
                axisLabel: {
                    color: "#FFF" //刻度线标签颜色
                }
            }
        ],
        series: [
            {
                name: '出生率(%)',
                type: 'line',
                barWidth: '40%',
                data: csl.value,
                color: "#7FFF00",
                smooth: true,
                areaStyle: {
                    normal: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgba(137, 189, 27, 0.3)'
                        }, {
                            offset: 0.8,
                            color: 'rgba(137, 189, 27, 0)'
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                        shadowBlur: 10
                    }
                },
            },
            {
                name: '死亡率(%)',
                type: 'line',
                barWidth: '40%',
                data: swl.value,
                color: "#FF0000",
                smooth: true,
                lineStyle: {
                    normal: {
                        width: 2
                    }
                },
                areaStyle: {
                    normal: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgba(255, 0, 0, 0.3)'
                        }, {
                            offset: 0.8,
                            color: 'rgba(0, 136, 212, 0)'
                        }], false),
                        shadowColor: 'rgba(0, 0, 0, 0.1)',
                        shadowBlur: 10
                    }
                },
            }
        ]
    };
    myChart.setOption(option);
    myChart.on('click', (e) => {
        scale.value = [
            { start: 14, end: 30 }, { start: 12, end: 14 },
            { start: 10, end: 12 }, { start: 8, end: 10 },
            { start: 6, end: 8 }, { start: 0, end: 6 },
        ];
        if (e.seriesName == '出生率(%)') {
            getpryear(e.data.name, '');
            getRKnumber(e.data.name, '出生率');
        } else {
            getpryear(e.data.name, '');
            getRKnumber(e.data.name, '死亡率');
        }
    });
}
function initmortality() {
    var myChart = echarts.init(mortality.value);
    let option = {
        color: ['#00FF00'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            x: 40,
            y: 30,
            x2: 5,
            y2: 20
        },
        calculable: true,
        xAxis: [{
            type: 'category',
            data: RKx.value,
            axisLabel: {
                color: "#FFF" //刻度线标签颜色
            }
        }],
        yAxis: [
            {

                type: "value",
                min: "0",
                axisLabel: {
                    color: "#FFF" //刻度线标签颜色
                }
            }
        ],
        series: [
            {
                name: '就业人口(万人)',
                type: 'bar',
                barWidth: '40%',
                data: employment.value,
                color: "#FF9900"
            }
        ]
    };
    myChart.setOption(option);
}
// myChart.showLoading();

function initmap() {
    let obj = {};
    obj.ad_code = ctcode.value;
    obj.year = currenyear.value;
    var myChart = echarts.init(mapmain.value);
    $sys.getGeomData(obj).then(res => {
        if (res.code == 200) {
            res.data.features.forEach((item, inde) => {
                item.properties.name = item.properties.ad_name;
            });
            echarts.registerMap(ctname.value, res.data, {

            });
            var option = {

                tooltip: {
                    trigger: 'item',
                },
                visualMap: {
                    show: true,
                    textStyle: { color: '#fff' },
                    x: 'left',
                    y: 'center',
                    splitList: scale.value,
                    color: ['#FF3300', '#FF9900', '#FFB09D', '#ffff00', '#00CC00', '#7FFF00']
                },
                toolbox: {
                    show: false,
                    //orient: 'vertical',
                    left: 'left',
                    top: 'top',
                    feature: {
                        dataView: { readOnly: false },
                        restore: {},
                        saveAsImage: {}
                    }
                },
                series: [
                    {
                        name: m_title.value,
                        type: 'map',
                        roam: true,
                        map: ctname.value,
                        label: {
                            show: true
                        },
                        emphasis: {
                            label: {
                                show: true,
                            }
                        },
                        data: rkdata.value
                    }
                ]
            };
            myChart.setOption(option);
            myChart.on('click', function (e) {

            });
        }
    });
}
</script>

<style lang="less">
#sshart {
    position: relative;
    height: 100%;
    .m_elbtn{
        background-color: #001547;
        color: #019CEE;
        border: 1px solid #019CEE;
    }
}

.yearlink:hover {
    color: #004cff;
}

.logo {
    position: fixed;
    height: 5%;
    z-index: 999;
    width: 100%;
    padding-top: 5px;
    padding-bottom: 10px;
    background-color: #061436;
}

#charts .m_sschart{
    display: flex;
    justify-content: space-between;
    background: url('../img/data08.png') no-repeat #000b3f;
    position: relative;
    background-size: cover;
    height: 93.7%;
    overflow: hidden;

    .charscon {
        width: 90%;
        margin: 0 auto;
        height: 32%;
        border: 1px #1c3074 solid;
        padding: 0px 15px 8px 15px;
        margin-top: 2%;
        background: #00164b;
    }

    .chartitle {
        margin-top: 10px;
        color: #cbcdd4;
        font-size: 18px;
        line-height: 35px;
    }

    .Chartleft {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        width: 25%;
        padding-bottom: 5px;

        #allRK {
            height: 200px;
        }

        #CZHl {
            height: 200px;
        }

        #allGDP {
            height: 200px;
        }
    }

    .Chartmiddle {
        width: 50%;

        .numbercount {
            display: flex;
            justify-content: space-around;

            margin: 10px auto;
            height: 130px;

            .numbercc {
                width: 18%;
                background: url('../img/ksh40.png') no-repeat;
                background-size: 100% 100%;
            }
        }

        .mapcon {
            position: relative;

            width: 98%;
            margin: 0 auto;
            margin-top: 20px;

            .datatitle {
                width: 100%;
                // background-color: #4d66e3;
                color: white;
                line-height: 30px;
                text-align: center;
                font-size: 24px;
            }

            .datacon {
                padding: 5px 10px 0px 10px;
                background: rgba(0, 22, 75, 0.5);
                width: 98%;
                margin: 0 auto;
                height: auto;
                color: #cbcdd4;
                display: flex;
                justify-content: flex-start;
                align-items: flex-start !important;
                flex-wrap: wrap;
                position: absolute;
                bottom: 1%;
                left: 50%;
                transform: translate(-50%, 0);

                .citylist {
                    width: 20%;
                    line-height: 34px;
                }
            }

            .lt {
                position: absolute;
                left: 0;
                top: 0;
            }

            .rt {
                position: absolute;
                right: 0;
                top: 0;
            }

            .rb {
                position: absolute;
                left: 0;
                bottom: 0;
            }

            .lb {
                position: absolute;
                right: 0;
                bottom: 0;
            }
        }

        // background-color: red;
        #mapmain {
            background: url('../img/ksh41.png') no-repeat;
            background-size: 100% 100%;
            width: 100%;
            min-height: 650px;
        }
    }

    .yj {
        color: white;
        font-family: "yjsz";
    }

    .dgtitle {
        text-align: center;
        color: #cbcdd4;
        font-size: 16px;
        line-height: 45px;
    }

    .dgnumber {
        color: #00deff;
        font-size: 46px;
        font-family: 'yjsz';
        // font-weight: 800;
        list-style: none;
        text-shadow: 0 0 25px #00d8ff;
        text-align: center;
    }

    .Chartright {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        width: 25%;
        padding-bottom: 5px;

        #RKdensity {
            height: 200px;
        }

        #natality {
            height: 200px;
        }

        #mortality {
            height: 200px;
        }
    }
}
</style>
